package us.icitap.cm.business.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.eclipse.persistence.annotations.Customizer;

import us.icitap.cm.utils.MyCustomizer;

@Entity
@Customizer(MyCustomizer.class)
@Table(name="WEAPON", schema="MPC")
public class Weapon implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -4318495021493943276L;


	@Id
	@Column(insertable=false, updatable = false)
	private Integer id;
	

	@OneToOne
	@JoinColumn(name="ID",nullable=false)
	private AppEntity appEntity;
	
	@ManyToOne
	@JoinColumn(name="WEAPON_CLASS_ID")
	private AppList classification;
	
	@ManyToOne
	@JoinColumn(name="WEAPON_TYPE_ID")
	private AppList weaponType;
	
	@ManyToOne
	@JoinColumn(name="WEAPON_MODEL_ID")
	private AppList weaponModel;
	
	@Column(length=500)
	private String notes;

	public Weapon() {
		// TODO Auto-generated constructor stub
	}
	
	public Weapon(Weapon weapon) {
		this.classification = weapon.getClassification();
		this.notes = weapon.getNotes();
		this.weaponModel = weapon.getWeaponModel();
		this.weaponType = weapon.getWeaponType();
		
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public AppEntity getAppEntity() {
		return appEntity;
	}

	public void setAppEntity(AppEntity appEntity) {
		this.appEntity = appEntity;
	}

	public AppList getClassification() {
		return classification;
	}

	public void setClassification(AppList classification) {
		this.classification = classification;
	}

	public AppList getWeaponType() {
		return weaponType;
	}

	public void setWeaponType(AppList weaponType) {
		this.weaponType = weaponType;
	}

	public AppList getWeaponModel() {
		return weaponModel;
	}

	public void setWeaponModel(AppList weaponModel) {
		this.weaponModel = weaponModel;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	

	@Override
	public String toString() {
		if(this.classification != null)
			if(this.weaponType != null)
				if(this.weaponModel != null) return this.classification.getTag() + ", " + this.weaponType.getTag() + ", " + this.getWeaponModel().getTag();
				else return this.classification.getTag() + ", " + this.weaponType.getTag();
			else return this.classification.getTag();
		else return "Arma nr. " + id;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((classification == null) ? 0 : classification.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((notes == null) ? 0 : notes.hashCode());
		result = prime * result
				+ ((weaponModel == null) ? 0 : weaponModel.hashCode());
		result = prime * result
				+ ((weaponType == null) ? 0 : weaponType.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Weapon other = (Weapon) obj;
		if (classification == null) {
			if (other.classification != null)
				return false;
		} else if (!classification.equals(other.classification))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (notes == null) {
			if (other.notes != null)
				return false;
		} else if (!notes.equals(other.notes))
			return false;
		if (weaponModel == null) {
			if (other.weaponModel != null)
				return false;
		} else if (!weaponModel.equals(other.weaponModel))
			return false;
		if (weaponType == null) {
			if (other.weaponType != null)
				return false;
		} else if (!weaponType.equals(other.weaponType))
			return false;
		return true;
	}
	
	public boolean myEquals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Weapon other = (Weapon) obj;
		if (classification == null) {
			if (other.classification != null)
				return false;
		} else if (!classification.equals(other.classification))
			return false;
		
		if (notes == null) {
			if (other.notes != null)
				return false;
		} else if (!notes.equals(other.notes))
			return false;
		if (weaponModel == null) {
			if (other.weaponModel != null)
				return false;
		} else if (!weaponModel.equals(other.weaponModel))
			return false;
		if (weaponType == null) {
			if (other.weaponType != null)
				return false;
		} else if (!weaponType.equals(other.weaponType))
			return false;
		return true;
	}
	
}
